package com.ai.platform.spider.core.collocate;

import com.ai.platform.spider.utils.Properties;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述 配置
 * 创建者 yeyingsheng
 * 创建时间 2018年06月22日
 */
public class Config {

    //种子
    private Seeds seeds;

    //属性
    private Properties params;

    private Docs docs;

    private Rules rules;

    public Config() {
        seeds = new Seeds();
        params = new Properties();
        docs=new Docs();
        rules=new Rules();
    }

    public interface Builder {
        Config build() throws Exception;
    }

    /**
     * 文档
     */
    public static class Docs{
        private List<Doc> docs;
        public Docs() {
            this.docs = new ArrayList<>();
        }

        public Docs add(Doc doc) {
            this.docs.add(doc);
            return this;
        }

        public List<Doc> all() {
            return this.docs;
        }
    }

    /**
     * 规则
     */
    public static class Rules{
        private List<Rule> rules;
        public Rules() {
            this.rules = new ArrayList<>();
        }

        public Rules add(Rule rule) {
            this.rules.add(rule);
            return this;
        }

        public List<Rule> all() {
            return this.rules;
        }
    }

    /**
     * 种子
     */
    public static class Seeds {
        private List<Seed> seeds;

        public Seeds() {
            this.seeds = new ArrayList<>();
        }

        public Seeds add(Seed seed) {
            this.seeds.add(seed);
            return this;
        }

        public Seeds add(String name, String url) {
            return this.add(new Seed(name, url));
        }

        public Seeds add(String url) {
            return this.add(new Seed(url));
        }

        public List<Seed> all() {
            return this.seeds;
        }
    }

    public Config addSeed(String url) {
        return this.addSeed(new Seed(url));
    }

    public Config addSeed(String name, String url) {
        return this.addSeed(new Seed(name, url));
    }

    public Config addSeed(Seed seed) {
        seeds.add(seed);
        return this;
    }

    public Seeds getSeeds() {
        return seeds;
    }

    public Properties getParams() {
        return params;
    }

    public Docs getDocs() {
        return docs;
    }

    public Config addDocs(Docs docs) {
        this.docs = docs;
        return this;
    }

    public Rules getRules() {
        return rules;
    }

    public Config addRules(Rules rules) {
        this.rules = rules;
        return this;
    }
}
